<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>AdWords API Documentation</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta><link rel="stylesheet" href="../css/template.css" type="text/css"></link></head><body><div id="content"><h1 class="file">Common/Util/XmlUtils.php</h1><div id="file-nav-box"><div id="file-nav-container"><ul id="file-nav"><li><a href="#classes"><img src="../images/icons/class.png" alt="Class" height="14"></img>
                          Classes
                      </a><ul><li><a href="#\XmlUtils">\XmlUtils</a></li></ul></li></ul><div style="clear: left;"></div></div><div id="file-nav-tab">
              Table of Contents
          </div></div><a name="top" class="anchor"></a><div id="file-description"><div class="short-description">A collection of utility methods for working with XML.</div><div class="long-description"><p>PHP version 5</p>

<p>Copyright 2011, Google Inc. All Rights Reserved.</p>

<p>Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at</p>

<pre><code>http://www.apache.org/licenses/LICENSE-2.0
</code></pre>

<p>Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.</p></div></div><dl class="file-info"><dt>Author</dt><dd>Adam Rogal
         
    </dd><dt>Author</dt><dd>Eric Koleda
         
    </dd><dt>Author</dt><dd>Vincent Tsao
         
    </dd><dt>Category</dt><dd>WebServices
         
    </dd><dt>Copyright</dt><dd>2011, Google Inc. All Rights Reserved.
         
    </dd><dt>License</dt><dd>http://www.apache.org/licenses/LICENSE-2.0 Apache License,
            Version 2.0
         
    </dd><dt>Package</dt><dd>GoogleApiAdsCommon
         
    </dd><dt>Subpackage</dt><dd>Util
         
    </dd></dl><a name="classes" class="anchor"></a><a id="\XmlUtils" class="anchor"></a><h2 class="class">\XmlUtils<div class="to-top"><a href="#top">jump to top</a></div></h2><div class="class"><small class="package"><b>Package: </b>GoogleApiAdsCommon\Util</small><div class="short-description">A collection of utility methods for working with XML.</div><div class="long-description"></div><dl class="class-info"></dl><h3>Methods</h3><div><a id="\XmlUtils::ConvertDocumentToObject()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">ConvertDocumentToObject</span><span class="nb-faded-text">(<a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a> $document)</span> : void</code><div class="description"><span class="attribute">static</span><p class="short_description">Converts a DOMDocument to a stdClass object, where each element under
the root node is a field.</p></div><div class="code-tabs"><div class="long-description"><p>Atribute values are ignored.</p></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$document</th><td><a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></td><td><em><p>the document to convert</p></em></td></tr></table><strong>Details</strong><dl class="function-info"><dt>Returns</dt><dd>Object the converted object
         
    </dd></dl></div><div class="clear"></div></div><a id="\XmlUtils::ConvertElementToObject()" class="anchor"></a><div class="method private"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_private.png" style="margin-right: 5px" alt="private"></img><span class="highlight">ConvertElementToObject</span><span class="nb-faded-text">(<a href="../files/http://php.net/manual/en/class.domelement.php">\DOMElement</a> $element)</span> : void</code><div class="description"><span class="attribute">static</span><p class="short_description">Converts a DOMElement to a stdClass object, where each child element is
a field.</p></div><div class="code-tabs"><div class="long-description"><p>Attribute values are ignored.</p></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$element</th><td><a href="../files/http://php.net/manual/en/class.domelement.php">\DOMElement</a></td><td><em><p>the element to convert</p></em></td></tr></table><strong>Details</strong><dl class="function-info"><dt>Returns</dt><dd>Object the converted object
         
    </dd></dl></div><div class="clear"></div></div><a id="\XmlUtils::ConvertNodeValueToObject()" class="anchor"></a><div class="method private"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_private.png" style="margin-right: 5px" alt="private"></img><span class="highlight">ConvertNodeValueToObject</span><span class="nb-faded-text">(string $value)</span> : mixed</code><div class="description"><span class="attribute">static</span><p class="short_description">Converts a node value to a PHP value of the appropriate type.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$value</th><td>string</td><td><em><p>the value of the node</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td>mixed</td><td>the PHP value as the appropriate type</td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::ConvertObjectToDocument()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">ConvertObjectToDocument</span><span class="nb-faded-text">(Object $object, string $rootElementName)</span> : <a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></code><div class="description"><span class="attribute">static</span><p class="short_description">Converts an object to a DOMDocument.</p></div><div class="code-tabs"><div class="long-description"><p>The root element name is passed in as
a parameter, and each field of the object becomes a child element. Array
values are represented by multiples instances of that element. Methods on
the object are ignored. There is no support for XML attributes.</p></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$object</th><td>Object</td><td><em><p>the object to serialize</p></em></td></tr><tr><th>$rootElementName</th><td>string</td><td><em><p>the name of the root element</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td><a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></td><td>the document representing the object</td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::ConvertObjectToElement()" class="anchor"></a><div class="method private"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_private.png" style="margin-right: 5px" alt="private"></img><span class="highlight">ConvertObjectToElement</span><span class="nb-faded-text">(Object $object, string $elementName, <a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a> $document)</span> : <a href="../files/http://php.net/manual/en/class.domelement.php">\DOMElement</a></code><div class="description"><span class="attribute">static</span><p class="short_description">Converts an object to an DOMElement.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$object</th><td>Object</td><td><em><p>the object to serialize</p></em></td></tr><tr><th>$elementName</th><td>string</td><td><em><p>the name of the element to serialize</p></em></td></tr><tr><th>$document</th><td><a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></td><td><em><p>the document that the element will be added to</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td><a href="../files/http://php.net/manual/en/class.domelement.php">\DOMElement</a></td><td>the element representing the object</td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::ConvertObjectToNodeValue()" class="anchor"></a><div class="method private"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_private.png" style="margin-right: 5px" alt="private"></img><span class="highlight">ConvertObjectToNodeValue</span><span class="nb-faded-text">(mixed $object)</span> : void</code><div class="description"><span class="attribute">static</span><p class="short_description">Converts a PHP value to a string for use in an XML node value.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$object</th><td>mixed</td><td><em><p>the PHP value</p></em></td></tr></table><strong>Details</strong><dl class="function-info"><dt>Returns</dt><dd>string the string value of the object
         
    </dd></dl></div><div class="clear"></div></div><a id="\XmlUtils::GetDomFromXml()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">GetDomFromXml</span><span class="nb-faded-text">(string $xml)</span> : <a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></code><div class="description"><span class="attribute">static</span><p class="short_description">Gets the DOMDocument of the <var>$xml</var>.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$xml</th><td>string</td><td><em><p>the XML to create a DOMDocument from</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td><a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></td><td>the DOMDocument of the XML</td></tr></table><strong>Throws</strong><table class="argument-info"><thead><tr><th>Exception</th><th>Description</th></tr></thead><tr><td><a href="../files/http://php.net/manual/en/class.domexception.php">\DOMException</a></td><td><em>if the DOM could not be loaded</em></td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::GetXmlFromDom()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">GetXmlFromDom</span><span class="nb-faded-text">(<a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a> $document)</span> : string</code><div class="description"><span class="attribute">static</span><p class="short_description">Gets the XML represenation of the document.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$document</th><td><a href="../files/http://php.net/manual/en/class.domdocument.php">\DOMDocument</a></td><td><em><p>the document to convert</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td>string</td><td>the XML represenation of the document</td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::HandleXmlError()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">HandleXmlError</span><span class="nb-faded-text">(string $errno, string $errstr, string $errfile, integer $errline)</span> : boolean</code><div class="description"><span class="attribute">static</span><p class="short_description">Caputures the warnings thrown by the loadXML function to create a proper
DOMException.</p></div><div class="code-tabs"><div class="long-description"></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$errno</th><td>string</td><td><em><p>contains the level of the error raised, as an integer</p></em></td></tr><tr><th>$errstr</th><td>string</td><td><em><p>contains the error message, as a string</p></em></td></tr><tr><th>$errfile</th><td>string</td><td><em><p>contains the filename that the error was raised in,
    as a string</p></em></td></tr><tr><th>$errline</th><td>integer</td><td><em><p>contains the line number the error was raised at,
    as an integer</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td>boolean</td><td>&lt;var&gt;FALSE&lt;/var&gt; if the normal error handler should
    continue</td></tr></table></div><div class="clear"></div></div><a id="\XmlUtils::PrettyPrint()" class="anchor"></a><div class="method public"><a href="#" class="gripper"><img src="../images/icons/arrow_right.png"></img><img src="../images/icons/arrow_down.png" style="display: none;"></img></a><code class="title"><img src="../images/icons/method.png" alt="method" title="method"></img><img src="../images/icons/visibility_public.png" style="margin-right: 5px" alt="public"></img><span class="highlight">PrettyPrint</span><span class="nb-faded-text">(string $xml)</span> : string</code><div class="description"><span class="attribute">static</span><p class="short_description">Returns a pretty printed XML.</p></div><div class="code-tabs"><div class="long-description"><p>If the XML cannot be loaded a string
stripped of any newlines is returned.</p></div><strong>Parameters</strong><table class="argument-info"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tr><th>$xml</th><td>string</td><td><em><p>the XML to pretty print</p></em></td></tr></table><strong>Returns</strong><table class="argument-info"><thead><tr><th>Type</th><th>Description</th></tr></thead><tr><td>string</td><td>a pretty printed string</td></tr></table></div><div class="clear"></div></div></div></div></div><small class="footer">
            Documentation was generated by
            <a href="http://phpdoc.org">phpDocumentor
                2.0.0a12</a>.
        </small></body></html>
